import 'package:flutter/material.dart';
import '../Models/FontSize.dart';
import '../Utils/DataManager.dart';
class MedicineChest extends StatefulWidget {
  @override
  _MedicineChestState createState() {
    return _MedicineChestState();
  }
}
class _MedicineChestState extends State< MedicineChest> {
  var list = [];
  @override
  Widget build(BuildContext context) {
    print("进入清单列表  " + context.toString());

    //定义列表widget的list
    List<Widget> list = <Widget>[];

    //根据Demo数据，构造列表ListTile组件list
    for (int index = 0; index < dataManager.getMedicineSize(); index++) {
      print("进入list");
      var drug = dataManager.getMedicine(index);
      list.add(
        ListTile(
          onTap: () {
            print("onPressed");
            Navigator.pushNamed(context, "addRemind", arguments: {"drug": drug})
                .then((val) {
              print(val);
              if (val != null) {
                setState(() {
                  dataManager.setMedicine(index, val);
                  dataManager.save();
                });
              }
            });
          },
          title: Text(
            drug.getName(),
            style: TextStyle(fontSize: oneSize),
          ),
          subtitle: Text(
            "每日 " +
                // drug.getTimes().length.toString() +
                drug.getNumber().toString()  +
                " 次，每次 " +
                drug.getUnit() + "片",
            //  +
            // " " +
            // drug.getUnit(),
            style: TextStyle(fontSize: oneSize),
          ),
          leading: Icon(
            Icons.fastfood,
            color: Colors.orange,
            size: oneSize,
          ),
          trailing: IconButton(
            icon: Icon(Icons.delete_forever,size: oneSize),
            onPressed: () {
              setState(
                    () {
                  dataManager.deleteMedicine(index);
                  dataManager.save();
                },
              );
            },
          ),
        ),
      );
    }
    //返回整个页面
    return Scaffold(
      body: ListView(
        children: list,
      ),
      persistentFooterButtons: <Widget>[
        FlatButton(
            child: Text(
              "返回",
              style: TextStyle(fontSize: oneSize),
            ),
            onPressed: () {
              Navigator.pop(context);
            }),

      ],
    );
  }

  /*@override
  Widget build(BuildContext context) {
    // TODO: implement build
    return ListView(
      children: <Widget>[
        Card(
          margin: EdgeInsets.fromLTRB(10,5,10,5),
          child: Column(
            children: <Widget>[
              ListTile(
                leading: Icon(Icons.access_alarm_sharp),
                title: Text(
                  '硫软膏，25g',
                  style: TextStyle(fontSize: 20),
                ),
                subtitle: Text('每日3次，每次1g'),
                trailing: Icon(Icons.delete_forever_sharp ),
              ),
            ],
          ),
        ),
        Card(
          margin: EdgeInsets.fromLTRB(10,5,10,5),
          child: Column(
            children: <Widget>[
              ListTile(
                leading: Icon(Icons.access_alarm_sharp),
                title: Text(
                  '溴吡斯的明片，60mg*60',
                  style: TextStyle(fontSize: 20),
                ),
                subtitle: Text('每日3次，每次1片'),
                trailing: Icon(Icons.delete_forever_sharp ),
              ),
            ],
          ),
        ),
        Card(
          margin: EdgeInsets.fromLTRB(10,5,10,5),
          child: Column(
            children: <Widget>[
              ListTile(
                leading: Icon(Icons.access_alarm_sharp),
                title: Text(
                  '珍宝丸，0.2g*60',
                  style: TextStyle(fontSize: 20),
                ),
                subtitle: Text('每日3次，每次5片'),
                trailing: Icon(Icons.delete_forever_sharp ),
              ),
            ],
          ),
        ),

        Container(
          alignment: Alignment.bottomCenter,
          width: 60.0,
          child: ElevatedButton(
            child: Text('按钮'),
            onPressed: () {
              setState(() {
                this.list.add('当前时间:' + '${DateTime.now()}');
              });
            },
          ),
        ),
        SizedBox(
          height: 20,
        ),
        Column(
          children: this.list.map((value) {
            return ListTile(
              title: Text(value),
            );
          }).toList(),
        ),

      ],
    );
  }*/
}